package com.example.datasever;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.example.datasever.bean.Student;
import com.example.datasever.db.DBDao;
import com.google.gson.Gson;

import java.util.Arrays;

public class MainActivity extends AppCompatActivity {

    private Student student;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }
    private void init() {
       // DBHelper.DB_NAME = "tests.db";

       student = new Student("1","小明", 10, "三年二班", "man","100");
       DBDao.getInstance().insert(student);

//       // DBDao.getInstance().clearAll();
//        DBHelper.DB_NAME = "tests.db";
       Gson gson = new Gson();//序列化
        String userJson = gson.toJson(DBDao.getInstance().query());//查看第四行数据
        Log.e("MainActivity", "db size is " + DBDao.getInstance().query().size());//存储了多少数据
//        Log.e("TTT", "db size is " + DBDao.getInstance().query().get(0).getClass());
//        Log.e("TTT", "db size is " + DBDao.getInstance().query().get(0).toString());
        Log.e("MainActivity", "数据 " + userJson);
//
 //       Log.e("MainActivity","表格列表"+DBDao.getInstance().tablesInDB());
        String[] arr = MyApplication.getContext().databaseList();//查询所有的数据库文件
        Log.e("MainActivity", "数据库列表" + Arrays.toString(arr));
        for (int i = 0; i < arr.length; i++) {
            MyApplication.getContext().deleteDatabase(arr[i]);//删除所有的数据库文件
        }

    }

}